home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 1992 August / info-mac-1992.iso / UNIX / Sun Audio Mac.txt < prev    next >
Internet Message Format  |  1992-08-29  |  5KB

  1. Date: Mon, 6 Apr 1992 08:50:21 PDT 
  2. From: Victor_J_Heintz.wbst128@xerox.com
  3.  
  4. Received: by launchpad.paa.xerox.com (4.1/SMI-4.0) id AA03010; Mon, 6 Apr 92 11:50:14 EDT
  5. Apparently-To: info-mac@sumex-aim.stanford:edu:xerox
  6.  
  7. I have attached a C program I wrote to convert Sun Microsystems u-law encoded 
  8. audio files to linear sound data files. The latter files can be read by
  9. SoundMover ("Open any" mode) and converted to Mac snd resources. Anyone with a
  10. Sun Sparcstation and a microphone ought to be able to make their own Mac sounds.
  11. You have to remember to set the sampling rate in SoundMover to the value encoded
  12. in the audio file (usually, if not always, 8.0 kHz.) SoundMaster will still want
  13. to play them at 7.4 kHz, I think, but they sound OK.
  14.  
  15. There is no Makefile. You can simply "cc" it on your Sparcstation. If someone
  16. incorporates this into a Mac utility (such as SoundMover, hint, hint) all I
  17. ask is a free copy.
  18.  
  19. Please upload this to an appropriate directory.
  20.  
  21. Vic Heintz
  22. vic:wbst128@xerox.com
  23.  
  24. >------------------------------------------------------------------------------<
  25. /* sun_audio2mac_linear.c
  26.  * This program was written April 6, 1992 by Victor J. Heintz
  27.  * (vic:wbst128@xerox.com) 
  28.  *
  29.  * Converts Sun Microsystems u-law encoded ".au" sound files to
  30.  * linear sound data files.  These files are compatible as input
  31.  * to SoundMover with the "Open any" option.
  32.  * Uses a look up table to translate u-law encoded sound bytes to
  33.  * linear sound bytes as used in Macintosh snd resources.
  34.  * The look-up table was generated by applying the audio_u2c macro
  35.  * defined in the Sun ulaw2linear.h file to values from 0 to 255.
  36.  * The audio file header structure was taken from the audio_filehdr.h
  37.  * file in the Sun SOUND demo package.
  38.  * I am distributing this freely in the hopes that someone will write
  39.  * a Mac tool that recognizes Sun u-law format sounds ( and of course
  40.  * let me have a free copy.)
  41.  */
  42.  
  43. #include <stdio.h>
  44.  
  45. #define    AU_MAGIC    0x2e736e64
  46. #define U_LAW        1
  47. #define    INFO_SIZE    (au_head.hdr_size - 24)
  48.  
  49. static unsigned char lut_au2snd[] = {
  50.       2,  6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 58, 62,
  51.      65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95,
  52.      96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111,
  53.     112,113,113,114,114,115,115,116,116,117,117,118,118,119,119,120,
  54.     120,120,121,121,121,121,122,122,122,122,123,123,123,123,124,124,
  55.     124,124,124,124,125,125,125,125,125,125,125,125,126,126,126,126,
  56.     126,126,126,126,126,126,126,126,127,127,127,127,127,127,127,127,
  57.     127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,128,
  58.     254,249,245,241,237,233,229,225,221,217,213,209,205,201,197,193,
  59.     190,188,186,184,182,180,178,176,174,172,170,168,166,164,162,160,
  60.     159,158,157,156,155,154,153,152,151,150,149,148,147,146,145,144,
  61.     143,142,142,141,141,140,140,139,139,138,138,137,137,136,136,135,
  62.     135,135,134,134,134,134,133,133,133,133,132,132,132,132,131,131,
  63.     131,131,131,131,130,130,130,130,130,130,130,130,129,129,129,129,
  64.     129,129,129,129,129,129,129,129,128,128,128,128,128,128,128,128,
  65.     128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128
  66.     };
  67.  
  68. typedef struct {
  69.     unsigned long    magic;        /* should be 0x2e736e64 = ".snd" */
  70.     unsigned long    hdr_size;    /* this struct's 24 bytes + info text */
  71.     unsigned long    data_size;    /* number of bytes of sound data */
  72.     unsigned long    encoding;    /* usually (always?) U_LAW = 1 */
  73.     unsigned long    sample_rate;    /* usually (always?) 8000 Hz */
  74.     unsigned long    channels;    /* usually (always?) 1 */
  75.     } au_hdrTYPE;
  76.  
  77. main(argc,argv)
  78. int argc;
  79. char *argv[];
  80. {
  81. au_hdrTYPE    au_head;
  82. FILE        *fpIn, *fpOut;
  83. char        info[255];    /* text immediately following header struct */
  84. unsigned char *sound_bytes;
  85. unsigned long whichByte;
  86.  
  87.     if (argc != 3) {
  88.         printf("Usage: %s Sun_audio_file Mac_snd_file\n", argv[0]);
  89.         exit (-1);
  90.         }
  91.     else {
  92.         fpIn = fopen(argv[1], "r");
  93.         if (fpIn == NULL) {
  94.             fprintf(stderr,"Error opening input file %s\n", argv[1]);
  95.             exit(-1);
  96.        }
  97.         fread(&au_head,sizeof(au_hdrTYPE), 1, fpIn);
  98.         if (au_head.magic != AU_MAGIC) {
  99.             fprintf(stderr,"%s is not a valid audio file!\n", argv[1]);
  100.             exit(-1);
  101.             }
  102.         fread(info,INFO_SIZE,1,fpIn);
  103.         printf("%s %ld Hz  %ld bytes: %s\n",argv[1], au_head.sample_rate,
  104.                 au_head.data_size, info);
  105.     if (au_head.encoding != U_LAW) {
  106.         fprintf(stderr,"Unknown data encoding!\n");
  107.         exit(-1);
  108.         }
  109.     fpOut = fopen(argv[2],"w");
  110.     if (fpOut == NULL) {
  111.         fprintf(stderr,"Error opening output file: %s\n", argv[2]);
  112.         exit(-1);
  113.         }
  114.     sound_bytes = (unsigned char *) malloc(au_head.data_size);
  115.     fread(sound_bytes, au_head.data_size, 1, fpIn);
  116.     for (whichByte = 0; whichByte < au_head.data_size; whichByte++) {
  117.         sound_bytes[whichByte] = lut_au2snd[sound_bytes[whichByte]];
  118.         }
  119.     fwrite(sound_bytes, au_head.data_size, 1, fpOut);
  120.     fclose(fpOut);
  121.     fclose(fpIn);
  122.     free(sound_bytes);
  123.     exit(0);
  124.         }
  125. }
  126.  
  127.  
  128.